<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of sealplayer
 *
 * @author Samuel
 */
class sealplayer_controller extends Controller {
    private $areaList;    //区号列表
    function _init()
    {
        check_level(50, segment(0), segment(1), segment(2, 'index'));
        $server_list=get_server_list();
        //var_dump($server_list);
        foreach($server_list as $k=>$row) {
            $this->areaList[$row['SvrOutAddr']] = $row['SvrID']."-".$row['SvrName'];
        }
    }

    function index()
    {
        if(is_submit())
        {
            $rowdata = $_POST['row'];
            //var_dump($rowdata);

            $post_data['SessionID']="ewewqw";
            $post_data['SessionKey']="wqqew";
            // 改成可以多人发送奖励
            //$post_data['TargetID']=(int)$rowdata['role_id'];
            $post_data['Level'] = (int)$rowdata['role_level'];
            $post_data['FightValueL'] = (int)$rowdata['role_fight_value_l'];
            $post_data['FightValueH'] = (int)$rowdata['role_fight_value_h'];

            $post_data['TargetIDs'] = array();
            $roleIds = explode(";", $rowdata['role_id']);
            print_r($roleIds);
            $roleIdCount = count($roleIds);

            for ($i=0;$i<$roleIdCount;$i++){
                array_push($post_data['TargetIDs'] , (int)($roleIds[$i]));
            }
            
            $post_data['Value']=(string)$rowdata['title'];

            foreach ($rowdata['item'] as $k=>$v){
                $item=array("ID"=>(int)$v,"Num"=>(int)$rowdata['amount'][$k]);
                $post_data['ItemLst'][$k]=$item;
            }
            //var_dump(json_encode($post_data));

            $strResult = vpost($rowdata['area_host'].'/send_award_to_player',3,json_encode($post_data));
            //echo $strResult;
            $result=json_decode($strResult,true);
            //操作失败或者连接失败
            if($result['RetCode'] == 0)
            {
                insert_log(translate('MENU_SEND_OBJECT'),translate('ADD'),NULL,$rowdata);
                echo "<script>alert('".translate('C_TIPS_SUCCESS_TEXT')."')</script>";
            }
            else
            {
                unset($rowdata);
                echo "<script>alert('".translate('C_TIPS_ERROR_TEXT')."')</script>";
            }
        }
        //var_dump($this->areaList);
        $this->view->assign("arealist", $this->form->select("row[area_host]", $this->areaList, '', array('id' => 'area_host')));
        $this->view->display("seal/delplayerobject/send");
    }

}

?>
